﻿CREATE PROCEDURE [dbo].[yaf_user_emails](
                @BoardID INT,
                @GroupID INT  = NULL)
AS
    BEGIN
        IF @GroupID = 0
        SET @GroupID = NULL
        IF @GroupID IS NULL
        SELECT a.Email
        FROM   yaf_User a
        WHERE  a.Email IS NOT NULL 
        AND a.BoardID = @BoardID
        AND a.Email IS NOT NULL
        AND a.Email <> ''
        ELSE
        SELECT a.Email
        FROM   yaf_User a
               JOIN yaf_UserGroup b
                 ON b.UserID = a.UserID
        WHERE  b.GroupID = @GroupID
        AND a.Email IS NOT NULL
        AND a.Email <> ''
    END


